[cli/linux] get plain text from raw emails (not attachments extraction)

Posted by etuardu on Stack Overflow See other posts from Stack Overflow or by etuardu
Published on 2011-01-10T15:50:06Z Indexed on 2011/01/10 15:53 UTC
Read the original article Hit count: 125

Filed under:
|
|
|
|

Hi, having a raw email as input (i.e. the text between "DATA" and "." sent by a smtp client) I need to extract the mail content (which I know is always text only) as plain text.

This means decoding transfer encoding (if any: could be base64 or quoted-printable), merging mutiparts (if any), and stripping headers.

I tried various tools that would do that: mewdecode, uudecode, uudeview... I only managed to get this last one to work, but it won't output anything if the mail is not MIME encoded and it stores its output in an unpredictable (nor forceable) filename, so it's hard to use it in a not-interactive shell script.

Since this is a pretty common job (every mail client have to do that), it's weird it's so complicated. Do you have some hints? (Actually, forcing uudeview to output in a certain file would be good enough).

Thank you!

© Stack Overflow or respective owner

Related posts about email

Related posts about base64